package com.huitone.smspfm.dao.oracle;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.util.StringUtils;

import com.huitone.smspfm.dao.oracle.entity.SmsSendRecord;


public class SmsSendRecordDao extends BaseDao<SmsSendRecord> {

	@Override
	public List<SmsSendRecord> getAllObj() {
		return jdbcTemplate.query("SELECT * FROM " + tableName + " WHERE STATUS = '1'", new BeanPropertyRowMapper<SmsSendRecord>(SmsSendRecord.class));
	}
	
	
	public SmsSendRecord getObj(String seqNum,String phone) {
		if(StringUtils.isEmpty(seqNum) || StringUtils.isEmpty(phone)){
			return null;
		}
		List<SmsSendRecord> list= jdbcTemplate.query("SELECT * FROM " + tableName 
				+ " WHERE SEND_CODE IS NOT NULL"
				+ " AND SM_SEQ =  '" +seqNum
				+ "' AND USER_NO = '" + phone
				+ "' ", new BeanPropertyRowMapper<SmsSendRecord>(SmsSendRecord.class));
		return (list != null && list.size() >0) ? list.get(0) : null;
	}
	
	public SmsSendRecord getObjForDay(String seqNum,String phone) {
		if(StringUtils.isEmpty(seqNum) || StringUtils.isEmpty(phone)){
			return null;
		}
		List<SmsSendRecord> list= jdbcTemplate.query("SELECT * FROM " + tableName 
				+ " WHERE "+"RECV_TIME >= (sysdate-1)" 
				+ "AND SEND_CODE IS NOT NULL"
				+ " AND SM_SEQ =  '" +seqNum
				+ "' AND USER_NO = '" + phone
				+ "' ", new BeanPropertyRowMapper<SmsSendRecord>(SmsSendRecord.class));
		return (list != null && list.size() >0) ? list.get(0) : null;
	}

}
